<?php
require_once "HTTP/Request.php";

echo '------- output from kt_sso-tester.php ------------------<br>';
echo 'This page simulates the 2 requests that KT will send to your joomla app to authenticate the user<p>';
echo 'Step 1: asking kt_sso.php for the name of the joomla session cookie (Are you logged into your joomla site now?)';
$req =& new HTTP_Request("http://localhost/corkcitysports/kt_sso.php"); //to debug change this to the url of your joomla site
$req->addQueryString('action','getCookieName');
$req->addQueryString('debug','true');
$req->sendRequest();
$cookieName = $req->getResponseBody();
$cookieValue=$_COOKIE[$cookieName];
echo '<br>Got a cookie name of '. $cookieName;
echo '<br>This cookie has a value of '. $cookieValue .'<br>';

echo '<br>Step 2: Now sending this cookie value to kt_sso.php to get the user name.<br>';
echo '---------- output below from kt_sso.php ---------------<br>';
$ip	= $_SERVER['REMOTE_ADDR'];
$agent = @$_SERVER['HTTP_USER_AGENT'];
$req->addQueryString('action','getUserName');
$req->addQueryString('sessid',$cookieValue);
$req->addQueryString('ip',$ip);
$req->addQueryString('agent',$agent);
$req->addQueryString('debug', 'true');
$req->sendRequest();

$user = $req->getResponseBody();
echo $user;
?>